import { Ellipsis } from '@/components/Ellipsis';
import '@/pages/design/style.less';
import type { tabType } from '@/pages/product/components/interfaceProduct';
import {
  batchConfirmDesignReview,
  commitDesignReview,
  confirmDesignReview,
  exportBatchProduct,
  getBatchProductByPage,
  getBopCodeAndName,
  issueWorkOrderInforByPage,
  setBop,
  updateBatchProduct,
  uploadWorkhourAndCycle,
} from '@/services/design/productDesign';
import { getProductTypeList } from '@/services/templateMaintain/inspectionTemplate';
import { tableSearchPublicConfig } from '@/utils/filterUtils';
import { filterTranNew, sortTran } from '@/utils/requestUtil';
import { EditOutlined, LogoutOutlined, PlusOutlined, UploadOutlined } from '@ant-design/icons';
import { PageHeaderWrapper } from '@ant-design/pro-layout';
import type { ActionType, ProColumns } from '@ant-design/pro-table';
import ProTable from '@ant-design/pro-table';
import { Button, Form, Input, message, Modal, notification, Select, Tabs, Upload } from 'antd';
import TextArea from 'antd/lib/input/TextArea';
import React, { useEffect, useRef, useState } from 'react';
import { history, useModel } from 'umi';
import type { recordInfoType } from './components/interfaceProduct';
import UnstandprocessInfo from './unstandprocessInfo';
const BatchProduct: React.FC<{}> = (props) => {
  const actionRef = useRef<ActionType>();
  const actionRef_2 = useRef<ActionType>();
  const actionRef_3 = useRef<ActionType>();
  const actionRef_4 = useRef<ActionType>();
  const actionRef_5 = useRef<ActionType>();
  const [modalVisit, setModalVisit] = useState(false); // 新建和编辑提示框
  const [confirmLoading, setConfirmLoading] = useState(false); //编辑框的disable
  const [formTitle, setFormTitle] = useState('添加工艺路径'); //
  const [formTitle2, setFormTitle2] = useState('审核'); //
  const [createOrUpdate, setCreateOrUpdate] = useState(false); //编辑框的disable
  const [theselectedRowKeys, settheSelectedRowKeys] = useState<React.Key[]>([]);
  const [modalVisit2, setModalVisit2] = useState(false); // 审核弹窗用到
  const [confirmLoading2, setConfirmLoading2] = useState(false);
  const [createOrUpdate2, setCreateOrUpdate2] = useState(false);
  const [file, setFile] = useState();
  const [theproductCode, settheproductCode] = useState(); //跳转页面用到
  const [thebatchProductId, setthebatchProductId] = useState();
  const [optionsbopCode, setoptionsbopCode] = useState([]);
  const [recordInfo, setrecordinfo] = useState<recordInfoType>();

  const [modalVisit3, setModalVisit3] = useState(false); // 工序工时弹窗
  const [form] = Form.useForm();
  const ref = useRef(null);

  const [modalVisit4, setModalVisit4] = useState(false); // 工时周期上传弹窗
  const [confirmLoading4, setConfirmLoading4] = useState(false);

  const [thebopcode, setthebopcode] = useState();
  const [theunStandTypeId, settheunStandTypeId] = useState();
  const [thetypecode, setthetypecode] = useState();
  const [thetypename, setthetypename] = useState();
  const [thedesc, setthedesc] = useState();

  const [selections, setSelections] = useState([]);
  const [handlenumber, sethandlenumber] = useState(''); //待审批的数量
  const [submitnumber, setsubmitnumber] = useState(''); //待提交的数量

  const { initialState } = useModel('@@initialState'); //hooks获取全局的共享的当前用户信息
  const [userRole, setUserRole] = useState<string[]>(); //当前用户的身份

  const [editingCell, setEditingCell] = useState(null); // 使用state跟踪柜体描述的编辑状态
  const [inputValue, setInputValue] = useState(''); //记录下点击柜体描述时的内容
  const [tabsActivekey, setTabsActivekey] = useState('0'); //tab页当前页面编号
  useEffect(() => {
    try {
      if (!initialState?.currentUser) {
        history.replace('/user/login');
        notification.error({
          message: '获取用户信息失败',
          description: '获取用户信息失败，将跳回到登录页面',
        });
        throw new Error('获取用户信息失败');
      }
      console.log('initialState', initialState);
      setUserRole(initialState.roleInfo);
    } catch (err) {
      console.log(err);
    }
  }, []);
  //选中selection中的序号
  const onSelectChange = (newSelectedRowKeys: React.Key[]) => {
    settheSelectedRowKeys(newSelectedRowKeys);
    console.log('已选择', newSelectedRowKeys);
  };

  const handleBlur = async (record: any) => {
    const temp: any = record;
    Modal.confirm({
      title: '变更柜体描述',
      content: '确认修改柜体描述吗？',
      okText: '确认',
      cancelText: '取消',
      onOk: async () => {
        if (record.productDesc === inputValue) {
          message.error('变更后的柜体描述不能与原始描述相同');
          record.productDesc = temp.productDesc;
          setInputValue('');
          setEditingCell(null);
        } else {
          let res = { ...record };
          res.productDesc = inputValue;
          console.log(res);
          const result = await updateBatchProduct(res);
          if (result.code === 0) {
            message.success('变更成功');
            setInputValue('');
            setEditingCell(null);
            actionRef.current!.reload();
          } else {
            message.error('变更失败');
          }
        }
      },
      onCancel: () => {
        record.productDesc = temp.productDesc;
        setInputValue('');
        setEditingCell(null);
      },
    });
  };

  // 待提交
  const tobeSubmitted: ProColumns[] = [
    {
      title: '序号',
      dataIndex: 'index',
      valueType: 'index',
      width: 50,
    },
    {
      title: '项目编号',
      dataIndex: 'projectCode',

      align: 'center',
      sorter: true,
      render: (text) => <>{Ellipsis(text)}</>,
      width: 120,
    },
    {
      title: '项目名称',
      dataIndex: 'projectName',

      align: 'center',
      sorter: true,
      render: (text) => <>{Ellipsis(text)}</>,
      width: 185,
    },

    {
      title: '当前批次',
      dataIndex: 'batchCountInfo',
      align: 'center',
      sorter: true,
      render: (text) => <>{Ellipsis(text)}</>,
      width: 120,
      search: false,
    },
    {
      title: '批次编号',
      dataIndex: 'batchPlanCode',

      align: 'center',
      sorter: true,
      render: (text) => <>{Ellipsis(text)}</>,
      width: 180,
    },
    // {
    //   title: '主计划编号',
    //   dataIndex: 'masterPlanCode',
    // },
    {
      title: '柜体编号',
      dataIndex: 'productCode',
      align: 'center',
      sorter: true,
      render: (text) => <>{Ellipsis(text)}</>,
      width: 190,
    },
    {
      title: '柜体描述',
      dataIndex: 'productDesc',
      align: 'center',
      sorter: true,
      ellipsis: true,
      ellipsis: true,
      width: 200,
      render: (text, record) => {
        if (editingCell === record.id) {
          // 编辑状态下显示InputNumber
          return (
            <Input
              defaultValue={record.productDesc}
              onChange={(e) => {
                setInputValue(e.target.value);
              }}
              onBlur={() => {
                setInputValue('');
                setEditingCell(null);
              }} // 失去焦点时取消编辑状态
              onPressEnter={() => handleBlur(record)} // 按下回车键时取消编辑状态
              autoFocus // 自动获取焦点
            />
          );
        } else {
          return (
            <div style={{ maxWidth: '150px', margin: '0 auto' }}>
              <span
                style={{ cursor: 'pointer' }}
                onClick={() => {
                  setEditingCell(record.id);
                  setInputValue(record.productDesc);
                }} // 点击时设置编辑状态
              >
                {text}
              </span>
              <EditOutlined style={{ color: 'green' }} />
            </div>
          );
        }
      },
    },
    {
      title: '批次交付日期',
      dataIndex: 'batchDeliveryDate',
      valueType: 'date',
      align: 'center',
      sorter: true,
      render: (text) => <>{Ellipsis(text)}</>,
      width: 120,
      search: false,
    },

    {
      title: '柜体类型',
      dataIndex: 'productType',
      align: 'center',
      width: 100,
      sorter: true,
      render: (text) => <>{Ellipsis(text)}</>,
      valueType: 'select',
      request: async () => {
        const getproduct = await getProductTypeList(null);
        const productOptionContract: any[] = [];
        getproduct.data.map((item: any, index: any) => {
          productOptionContract.push({ value: item, label: item });
        });
        return productOptionContract;
      },
    },
    {
      title: '是否标准柜体',
      dataIndex: 'isStandard',

      valueType: 'select',
      request: async () => [
        { label: '是', value: 1 },
        { label: '否', value: 0 },
      ],
      render: (text, record, _, action) => {
        return <div>{record.isStandard == 1 ? '是' : '否'}</div>;
      },
      align: 'center',
      sorter: true,
      width: 120,
    },
    {
      title: '技术工程师',
      dataIndex: 'engineer',
      width: 120,
      align: 'center',
      sorter: true,
      render: (text) => <>{Ellipsis(text)}</>,
    },
    {
      title: '审核人员',
      dataIndex: 'reviewEditor',

      align: 'center',
      sorter: true,
      render: (text, record) => <>{record.isStandard === 1 ? '系统' : Ellipsis(text)}</>,
    },
    {
      title: '审核状态',
      dataIndex: 'reviewState',
      search: false,
      width: 100,
      align: 'center',
      sorter: true,
      valueType: 'select',
      request: async () => [
        { label: '待提交', value: 0 },
        { label: '待审批', value: 1 },
        { label: '已审批', value: 2 },
        { label: '再提交', value: 3 },
      ],
      render: (text, record, _, action) => {
        return (
          <div>
            {record.reviewState == 0
              ? '待提交'
              : record.reviewState == 1
              ? '待审批'
              : record.reviewState == 2
              ? '已审批'
              : '再提交'}
          </div>
        );
      },
    },
    {
      title: '状态',
      dataIndex: 'state',

      align: 'center',
      sorter: true,
      width: 90,
      valueType: 'select',
      request: async () => [
        { label: '未下发', value: 0 },
        { label: '设计中', value: 1 },
        { label: '工单下发', value: 2 },
        { label: '生产中', value: 3 },
      ],
      render: (text, record, _, action) => {
        return (
          <div>
            {record.state == 0
              ? '未下发'
              : record.state == 1
              ? '设计中'
              : record.state == 2
              ? '工单下发'
              : '生产中'}
          </div>
        );
      },
    },
    {
      title: 'BOM上传',
      dataIndex: 'bomId',
      align: 'center',
      sorter: true,
      width: 100,
      search: false,
      render: (text, record, _, action) => {
        return <div>{record.bomId == null ? '未上传' : '已上传'}</div>;
      },
    },
    {
      title: '图纸上传',
      dataIndex: 'isDrawingUploaded',
      align: 'center',
      sorter: true,
      width: 100,
      search: false,
      render: (text, record, _, action) => {
        return <div>{record.isDrawingUploaded === 0 ? '未上传' : '已上传'}</div>;
      },
    },
    {
      title: '工时设置',
      dataIndex: 'isStdWorkHourUploaded',

      align: 'center',
      sorter: true,
      width: 100,
      search: false,
      render: (text, record, _, action) => {
        return <div>{record.isStdWorkHourUploaded == 1 ? '已设置' : '未设置'}</div>;
      },
    },
    {
      title: '工艺路径',
      dataIndex: 'bopCode',

      align: 'center',
      sorter: true,
      render: (text) => <>{Ellipsis(text)}</>,
    },
    {
      title: '计划分料开始日期',
      dataIndex: 'stageDosingStartTime',
      width: 100,
      search: false,
      align: 'center',
      sorter: true,
      render: (text) => <>{Ellipsis(text)}</>,
    },
    {
      title: '计划设计开始日期',
      dataIndex: 'planDesignStartDate',
      width: 100,
      search: false,
      valueType: 'date',
      align: 'center',
      sorter: true,
      render: (text) => <>{Ellipsis(text)}</>,
    },
    {
      title: '计划设计结束日期',
      dataIndex: 'planDesignEndDate',
      width: 100,
      search: false,
      valueType: 'date',
      align: 'center',
      sorter: true,
      render: (text) => <>{Ellipsis(text)}</>,
    },
    // {
    //   title: '计划设计工时',
    //   dataIndex: 'planDesignWh',
    //
    //  align: 'center',sorter: true,
    //   render: (text) => <>{Ellipsis(text)}</>,
    // },
    {
      title: '实际设计结束日期',
      dataIndex: 'actualKickoffStartDate',
      width: 100,
      search: false,
      valueType: 'date',
      align: 'center',
      sorter: true,
      render: (text) => <>{Ellipsis(text)}</>,
    },
    {
      title: '操作',
      valueType: 'option',
      key: 'option',
      fixed: 'right',
      align: 'center',
      width: 200,
      render: (text, record, _, action) => [
        <a
          key="BOMkey1"
          onClick={() => {
            history.push({
              pathname: '/design/productBomOverview',
              state: {
                productCode: record.productCode,
                batchProductId: record.id,
                reviewState: tabsActivekey,
                projectName: record.projectName,
              },
            });
          }}
        >
          设计
        </a>,
        <a
          key="checkKey1"
          hidden={!userRole?.includes('ROLE_TechOperator') && !userRole?.includes('ROLE_Admin')}
          onClick={async () => {
            console.log(record);
            const result = await commitDesignReview({ batchProductId: record.id });
            if (result != null) {
              message.success('提交成功');
            }
            actionRef.current?.reload();
            actionRef_2.current?.reload();
          }}
        >
          提交
        </a>,
        /*         <a
          key="drawingkey1"
          onClick={() => {
            history.push({
              pathname: '/design/productDrawingInfo',
              state: {
                productCode: record.productCode,
                batchProductId: record.id,
                reviewState: record.reviewState,
              },
            });
          }}
        >
          文件
        </a>, */
        /*         <a
          key="productbopKey1"
          onClick={async () => {
            if (record.isStandard == 1) {
              message.warning('标准柜体不能修改工艺路径');
            } else if (record.bopIsChange == 1) {
              message.warning('不能再次修改工艺路径');
            } else {
              setModalVisit(true);
              setCreateOrUpdate(true);
              setFormTitle('添加工艺路径');
              form.setFieldsValue({
                bopCode: optionsbopCode[0].value,
                unStandTypeId: record.id,
                productCode: record.productCode,
                productDesc: record.productDesc,
              });
            }
          }}
        >
          工艺
        </a>,
        <a
          key="processinfoKey1"
          onClick={() => {
            settheunStandTypeId(record.id);
            setthebopcode(record.bopCode);
            setthetypecode(record.productCode);
            setthetypename(record.productType);
            setthedesc(record.productDesc);
            setModalVisit3(true);
          }}
        >
          工时
        </a>, */
        <a
          key="fileinfo1"
          onClick={() => {
            history.push({
              pathname: '/design/fileInfo',
              state: {
                infoId: record.infoId,
                reviewState: tabsActivekey,
              },
            });
          }}
        >
          附件
        </a>,
      ],
    },
  ];

  // 待审批
  const tobeexamine: ProColumns[] = [
    {
      title: '序号',
      dataIndex: 'index',
      valueType: 'index',
      width: 50,
    },
    {
      title: '项目编号',
      dataIndex: 'projectCode',

      align: 'center',
      sorter: true,
      render: (text) => <>{Ellipsis(text)}</>,
      width: 120,
    },
    {
      title: '项目名称',
      dataIndex: 'projectName',

      align: 'center',
      sorter: true,
      render: (text) => <>{Ellipsis(text)}</>,
      width: 185,
    },

    {
      title: '当前批次',
      dataIndex: 'batchCountInfo',
      align: 'center',
      sorter: true,
      render: (text) => <>{Ellipsis(text)}</>,
      width: 120,
      search: false,
    },
    {
      title: '批次编号',
      dataIndex: 'batchPlanCode',

      align: 'center',
      sorter: true,
      render: (text) => <>{Ellipsis(text)}</>,
      width: 180,
    },
    {
      title: '柜体编号',
      dataIndex: 'productCode',

      align: 'center',
      sorter: true,
      render: (text) => <>{Ellipsis(text)}</>,
      width: 190,
    },
    {
      title: '柜体描述',
      dataIndex: 'productDesc',
      align: 'center',
      sorter: true,
      ellipsis: true,
      width: 200,
      render: (text) => <>{Ellipsis(text)}</>,
    },
    {
      title: '批次交付日期',
      dataIndex: 'batchDeliveryDate',
      valueType: 'date',
      align: 'center',
      sorter: true,
      render: (text) => <>{Ellipsis(text)}</>,
      width: 120,
      search: false,
    },

    // {
    //   title: '主计划编号',
    //   dataIndex: 'masterPlanCode',
    // },
    {
      title: '柜体类型',
      dataIndex: 'productType',

      align: 'center',
      sorter: true,
      render: (text) => <>{Ellipsis(text)}</>,
      valueType: 'select',
      request: async () => {
        const getproduct = await getProductTypeList(null);
        const productOptionContract: any[] = [];
        getproduct.data.map((item: any, index: any) => {
          productOptionContract.push({ value: item, label: item });
        });
        return productOptionContract;
      },
    },
    {
      title: '是否标准柜体',
      dataIndex: 'isStandard',

      align: 'center',
      sorter: true,
      valueType: 'select',
      request: async () => [
        { label: '是', value: 1 },
        { label: '否', value: 0 },
      ],
      render: (text, record, _, action) => {
        return <div>{record.isStandard == 1 ? '是' : '否'}</div>;
      },
      width: 120,
    },
    {
      title: '技术工程师',
      dataIndex: 'engineer',

      align: 'center',
      sorter: true,
      render: (text) => <>{Ellipsis(text)}</>,
    },
    {
      title: '审核人员',
      dataIndex: 'reviewEditor',

      align: 'center',
      sorter: true,
      render: (text, record) => <>{record.isStandard === 1 ? '系统' : Ellipsis(text)}</>,
    },
    {
      title: '审核状态',
      dataIndex: 'reviewState',

      search: false,
      align: 'center',
      sorter: true,
      valueType: 'select',
      request: async () => [
        { label: '待提交', value: 0 },
        { label: '待审批', value: 1 },
        { label: '已审批', value: 2 },
        { label: '已驳回', value: 3 },
      ],
      render: (text, record, _, action) => {
        return (
          <div>
            {record.reviewState == 0
              ? '待提交'
              : record.reviewState == 1
              ? '待审批'
              : record.reviewState == 2
              ? '已审批'
              : '已驳回'}
          </div>
        );
      },
    },
    {
      title: '工艺路径',
      dataIndex: 'bopCode',

      align: 'center',
      sorter: true,
      render: (text) => <>{Ellipsis(text)}</>,
    },
    {
      title: '计划分料开始日期',
      dataIndex: 'stageDosingStartTime',
      width: 100,
      align: 'center',
      sorter: true,
      render: (text) => <>{Ellipsis(text)}</>,
    },
    {
      title: '计划设计开始日期',
      dataIndex: 'planDesignStartDate',
      width: 100,
      search: false,
      valueType: 'date',
      align: 'center',
      sorter: true,
      render: (text) => <>{Ellipsis(text)}</>,
    },
    {
      title: '计划设计结束日期',
      dataIndex: 'planDesignEndDate',
      width: 100,
      search: false,
      valueType: 'date',
      align: 'center',
      sorter: true,
      render: (text) => <>{Ellipsis(text)}</>,
    },
    // {
    //   title: '计划设计工时',
    //   dataIndex: 'planDesignWh',
    //
    //  align: 'center',sorter: true,
    //   render: (text) => <>{Ellipsis(text)}</>,
    // },
    {
      title: '实际设计结束日期',
      dataIndex: 'actualKickoffStartDate',
      width: 100,
      search: false,
      valueType: 'date',
      align: 'center',
      sorter: true,
      render: (text) => <>{Ellipsis(text)}</>,
    },
    {
      title: '提交时间',
      dataIndex: 'submitTime',

      search: false,
      align: 'center',
      sorter: true,
      render: (text) => <>{Ellipsis(text)}</>,
      width: 145,
    },
    {
      title: '操作',
      valueType: 'option',
      key: 'option',
      fixed: 'right',
      align: 'center',
      width: 180,
      render: (text, record, _, action) => [
        <a
          key="checkKey2"
          hidden={!userRole?.includes('ROLE_TechManager') && !userRole?.includes('ROLE_Admin')}
          onClick={() => {
            // if (record.reviewState != 1) {
            setModalVisit2(true);
            setCreateOrUpdate2(true);
            setFormTitle2('审核');
            form.setFieldsValue({
              batchProductId: record.id,
            });
            // }
          }}
        >
          审核
        </a>,
        <a
          key="BOMkey2"
          onClick={() => {
            history.push({
              pathname: '/design/productBomOverview',
              state: {
                productCode: record.productCode,
                batchProductId: record.id,
                reviewState: record.reviewState,
                projectName: record.projectName,
              },
            });
          }}
        >
          查看
        </a>,
        /*         <a
          key="drawingkey2"
          onClick={() => {
            history.push({
              pathname: '/design/productDrawingInfo',
              state: {
                productCode: record.productCode,
                batchProductId: record.id,
                reviewState: record.reviewState,
              },
            });
          }}
        >
          文件
        </a>, */ //与设计合并为一个按钮
        <a
          key="fileinfo2"
          onClick={() => {
            history.push({
              pathname: '/design/fileInfo',
              state: {
                infoId: record.infoId,
                reviewState: record.reviewState,
              },
            });
          }}
        >
          附件
        </a>,
      ],
    },
  ];

  // 已审批
  const examined: ProColumns[] = [
    {
      title: '序号',
      dataIndex: 'index',
      valueType: 'index',
      width: 50,
    },
    {
      title: '项目编号',
      dataIndex: 'projectCode',

      align: 'center',
      sorter: true,
      render: (text) => <>{Ellipsis(text)}</>,
      width: 120,
    },
    {
      title: '项目名称',
      dataIndex: 'projectName',

      align: 'center',
      sorter: true,
      render: (text) => <>{Ellipsis(text)}</>,
      width: 185,
    },
    {
      title: '当前批次',
      dataIndex: 'batchCountInfo',
      align: 'center',
      sorter: true,
      render: (text) => <>{Ellipsis(text)}</>,
      width: 120,
      search: false,
    },
    {
      title: '批次编号',
      dataIndex: 'batchPlanCode',

      align: 'center',
      sorter: true,
      render: (text) => <>{Ellipsis(text)}</>,
      width: 180,
    },
    {
      title: '柜体编号',
      dataIndex: 'productCode',

      align: 'center',
      sorter: true,
      render: (text) => <>{Ellipsis(text)}</>,
      width: 190,
    },
    {
      title: '柜体描述',
      dataIndex: 'productDesc',
      align: 'center',
      sorter: true,
      render: (text) => <>{Ellipsis(text)}</>,
      width: 200,
    },
    {
      title: '批次交付日期',
      dataIndex: 'batchDeliveryDate',
      valueType: 'date',
      align: 'center',
      sorter: true,
      render: (text) => <>{Ellipsis(text)}</>,
      width: 120,
      search: false,
    },

    // {
    //   title: '主计划编号',
    //   dataIndex: 'masterPlanCode',
    // },

    {
      title: '柜体类型',
      dataIndex: 'productType',

      align: 'center',
      sorter: true,
      render: (text) => <>{Ellipsis(text)}</>,
      valueType: 'select',
      request: async () => {
        const getproduct = await getProductTypeList(null);
        const productOptionContract: any[] = [];
        getproduct.data.map((item: any, index: any) => {
          productOptionContract.push({ value: item, label: item });
        });
        return productOptionContract;
      },
    },
    {
      title: '是否标准柜体',
      dataIndex: 'isStandard',

      align: 'center',
      sorter: true,
      valueType: 'select',
      request: async () => [
        { label: '是', value: 1 },
        { label: '否', value: 0 },
      ],
      render: (text, record, _, action) => {
        return <div>{record.isStandard == 1 ? '是' : '否'}</div>;
      },
      width: 120,
    },
    {
      title: '技术工程师',
      dataIndex: 'engineer',

      align: 'center',
      sorter: true,
      render: (text) => <>{Ellipsis(text)}</>,
    },
    {
      title: '审核人员',
      dataIndex: 'reviewEditor',

      align: 'center',
      sorter: true,
      render: (text, record) => <>{record.isStandard === 1 ? '系统' : Ellipsis(text)}</>,
    },
    {
      title: '审核状态',
      dataIndex: 'reviewState',

      search: false,
      align: 'center',
      sorter: true,
      valueType: 'select',
      request: async () => [
        { label: '待提交', value: 0 },
        { label: '待审批', value: 1 },
        { label: '已审批', value: 2 },
        { label: '已驳回', value: 3 },
      ],
      render: (text, record, _, action) => {
        return (
          <div>
            {record.reviewState == 0
              ? '待提交'
              : record.reviewState == 1
              ? '待审批'
              : record.reviewState == 2
              ? '已审批'
              : '已驳回'}
          </div>
        );
      },
    },
    {
      title: '状态',
      dataIndex: 'state',

      align: 'center',
      sorter: true,
      valueType: 'select',
      request: async () => [
        { label: '未下发', value: 0 },
        { label: '设计中', value: 1 },
        { label: '工单下发', value: 2 },
        { label: '生产中', value: 3 },
      ],
      render: (text, record, _, action) => {
        return (
          <div>
            {record.state == 0
              ? '未下发'
              : record.state == 1
              ? '设计中'
              : record.state == 2
              ? '工单下发'
              : '生产中'}
          </div>
        );
      },
    },
    {
      title: '工艺路径',
      dataIndex: 'bopCode',

      align: 'center',
      sorter: true,
      render: (text) => <>{Ellipsis(text)}</>,
    },
    {
      title: '计划分料开始日期',
      dataIndex: 'stageDosingStartTime',
      align: 'center',
      width: 100,
      sorter: true,
      render: (text) => <>{Ellipsis(text)}</>,
    },
    {
      title: '计划设计开始日期',
      dataIndex: 'planDesignStartDate',
      width: 100,
      search: false,
      valueType: 'date',
      align: 'center',
      sorter: true,
      render: (text) => <>{Ellipsis(text)}</>,
    },
    {
      title: '计划设计结束日期',
      dataIndex: 'planDesignEndDate',
      width: 100,
      search: false,
      valueType: 'date',
      align: 'center',
      sorter: true,
      render: (text) => <>{Ellipsis(text)}</>,
    },
    // {
    //   title: '计划设计工时',
    //   dataIndex: 'planDesignWh',
    //
    //  align: 'center',sorter: true,
    //   render: (text) => <>{Ellipsis(text)}</>,
    // },
    {
      title: '实际设计结束日期',
      dataIndex: 'actualKickoffStartDate',
      width: 100,
      search: false,
      valueType: 'date',
      align: 'center',
      sorter: true,
      render: (text) => <>{Ellipsis(text)}</>,
    },
    {
      title: '审核描述',
      dataIndex: 'reviewMemo',
      align: 'center',
      sorter: true,
      search: false,
      render: (text) => <>{Ellipsis(text)}</>,
    },
    {
      title: '提交时间',
      dataIndex: 'submitTime',

      search: false,
      align: 'center',
      sorter: true,
      render: (text) => <>{Ellipsis(text)}</>,
      width: 145,
    },
    {
      title: '操作',
      valueType: 'option',
      key: 'option',
      fixed: 'right',
      align: 'center',
      width: 140,
      render: (text, record, _, action) => [
        <a
          key="BOMkey3"
          onClick={() => {
            history.push({
              pathname: '/design/productNosubmittedBomOverview',
              state: {
                productCode: record.productCode,
                batchProductId: record.id,
                reviewState: record.reviewState,
                projectName: record.projectName,
              },
            });
          }}
        >
          变更
        </a>,
        // <a
        //   key="drawingkey3"
        //   onClick={() => {
        //     history.push({
        //       pathname: '/design/productDrawingInfo',
        //       state: {
        //         productCode: record.productCode,
        //         batchProductId: record.id,
        //         reviewState: record.reviewState,
        //       },
        //     });
        //   }}
        // >
        //   文件
        // </a>,
        <a
          key="fileinfo3"
          onClick={() => {
            history.push({
              pathname: '/design/fileInfo',
              state: {
                infoId: record.infoId,
                reviewState: record.reviewState,
              },
            });
          }}
        >
          附件
        </a>,
      ],
    },
  ];

  // 已驳回
  const issued: ProColumns[] = [
    {
      title: '序号',
      dataIndex: 'index',
      valueType: 'index',
      width: 50,
    },
    {
      title: '项目编号',
      dataIndex: 'projectCode',

      align: 'center',
      sorter: true,
      render: (text) => <>{Ellipsis(text)}</>,
      width: 120,
    },
    {
      title: '项目名称',
      dataIndex: 'projectName',

      align: 'center',
      sorter: true,
      render: (text) => <>{Ellipsis(text)}</>,
      width: 185,
    },

    {
      title: '当前批次',
      dataIndex: 'batchCountInfo',
      align: 'center',
      sorter: true,
      render: (text) => <>{Ellipsis(text)}</>,
      width: 120,
      search: false,
    },
    {
      title: '批次编号',
      dataIndex: 'batchPlanCode',

      align: 'center',
      sorter: true,
      render: (text) => <>{Ellipsis(text)}</>,
      width: 180,
    },
    {
      title: '柜体编号',
      dataIndex: 'productCode',

      align: 'center',
      sorter: true,
      render: (text) => <>{Ellipsis(text)}</>,
      width: 190,
    },
    {
      title: '柜体描述',
      dataIndex: 'productDesc',
      ellipsis: true,
      align: 'center',
      sorter: true,
      render: (text) => <>{Ellipsis(text)}</>,
      width: 200,
    },
    {
      title: '批次交付日期',
      dataIndex: 'batchDeliveryDate',
      align: 'center',
      sorter: true,
      render: (text) => <>{Ellipsis(text)}</>,
      width: 120,
      search: false,
    },

    // {
    //   title: '主计划编号',
    //   dataIndex: 'masterPlanCode',
    // },

    {
      title: '柜体类型',
      dataIndex: 'productType',

      align: 'center',
      sorter: true,
      render: (text) => <>{Ellipsis(text)}</>,
      valueType: 'select',
      request: async () => {
        const getproduct = await getProductTypeList(null);
        const productOptionContract: any[] = [];
        getproduct.data.map((item: any, index: any) => {
          productOptionContract.push({ value: item, label: item });
        });
        return productOptionContract;
      },
    },
    {
      title: '是否标准柜体',
      dataIndex: 'isStandard',

      align: 'center',
      sorter: true,
      valueType: 'select',
      request: async () => [
        { label: '是', value: 1 },
        { label: '否', value: 0 },
      ],
      render: (text, record, _, action) => {
        return <div>{record.isStandard == 1 ? '是' : '否'}</div>;
      },
      width: 120,
    },
    {
      title: '技术工程师',
      dataIndex: 'engineer',

      align: 'center',
      sorter: true,
      render: (text) => <>{Ellipsis(text)}</>,
    },
    {
      title: '审核人员',
      dataIndex: 'reviewEditor',

      align: 'center',
      sorter: true,
      render: (text, record) => <>{record.isStandard === 1 ? '系统' : Ellipsis(text)}</>,
    },
    {
      title: '审核状态',
      dataIndex: 'reviewState',
      search: false,
      align: 'center',
      sorter: true,
      valueType: 'select',
      request: async () => [
        { label: '待提交', value: 0 },
        { label: '待审批', value: 1 },
        { label: '已审批', value: 2 },
        { label: '已驳回', value: 3 },
      ],
      render: (text, record, _, action) => {
        return (
          <div>
            {record.reviewState == 0
              ? '待提交'
              : record.reviewState == 1
              ? '待审批'
              : record.reviewState == 2
              ? '已审批'
              : '已驳回'}
          </div>
        );
      },
    },
    {
      title: '状态',
      dataIndex: 'state',
      align: 'center',
      sorter: true,
      valueType: 'select',
      request: async () => [
        { label: '未下发', value: 0 },
        { label: '设计中', value: 1 },
        { label: '工单下发', value: 2 },
        { label: '生产中', value: 3 },
      ],
      render: (text, record, _, action) => {
        return (
          <div>
            {record.state == 0
              ? '未下发'
              : record.state == 1
              ? '设计中'
              : record.state == 2
              ? '工单下发'
              : '生产中'}
          </div>
        );
      },
    },
    {
      title: '工艺路径',
      dataIndex: 'bopCode',

      align: 'center',
      sorter: true,
      render: (text) => <>{Ellipsis(text)}</>,
    },
    {
      title: '计划分料开始日期',
      dataIndex: 'stageDosingStartTime',
      width: 100,
      align: 'center',
      sorter: true,
      render: (text) => <>{Ellipsis(text)}</>,
    },
    {
      title: '计划设计开始日期',
      dataIndex: 'planDesignStartDate',
      width: 100,
      search: false,
      align: 'center',
      sorter: true,
      render: (text) => <>{Ellipsis(text)}</>,
    },
    {
      title: '计划设计结束日期',
      dataIndex: 'planDesignEndDate',
      width: 100,
      search: false,
      align: 'center',
      sorter: true,
      render: (text) => <>{Ellipsis(text)}</>,
    },
    // {
    //   title: '计划设计工时',
    //   dataIndex: 'planDesignWh',
    //
    //  align: 'center',sorter: true,
    //   render: (text) => <>{Ellipsis(text)}</>,
    // },
    {
      title: '实际设计结束日期',
      dataIndex: 'actualKickoffStartDate',
      width: 100,
      search: false,
      align: 'center',
      sorter: true,
      render: (text) => <>{Ellipsis(text)}</>,
    },
    {
      title: '驳回原因',
      dataIndex: 'reviewMemo',
      align: 'center',
      sorter: true,
      search: false,
      render: (text) => <>{Ellipsis(text)}</>,
    },
    {
      title: '提交时间',
      dataIndex: 'submitTime',

      search: false,
      align: 'center',
      sorter: true,
      render: (text) => <>{Ellipsis(text)}</>,
      width: 145,
    },
    {
      title: '操作',
      valueType: 'option',
      key: 'option',
      fixed: 'right',
      align: 'center',
      width: 265,
      render: (text, record, _, action) => [
        //已驳回不需要提交功能
        // <a
        //   key="checkKey4"
        //   onClick={async () => {
        //     const result = await commitDesignReview({ batchProductId: record.id });
        //     // console.log(record.id);
        //     if (result != null) {
        //       message.success('提交成功');
        //     }
        //     actionRef_4.current!.reload();
        //   }}
        // >
        //   提交
        // </a>,
        <a
          key="BOMkey4"
          onClick={() => {
            history.push({
              pathname: '/design/productBomOverview',
              state: {
                productCode: record.productCode,
                batchProductId: record.id,
                reviewState: record.reviewState,
                projectName: record.projectName,
              },
            });
          }}
        >
          设计
        </a>,
        <a
          key="drawingkey4"
          onClick={() => {
            history.push({
              pathname: '/design/productDrawingInfo',
              state: {
                productCode: record.productCode,
                batchProductId: record.id,
                reviewState: record.reviewState,
              },
            });
          }}
        >
          文件
        </a>,
        <a
          key="productbopKey4"
          onClick={async () => {
            if (record.isStandard == 1) {
              message.warning('标准柜体不能修改工艺路径');
            } else if (record.bopIsChange == 1) {
              message.warning('不能再次修改工艺路径');
            } else {
              setModalVisit(true);
              setCreateOrUpdate(true);
              setFormTitle('添加工艺路径');
              form.setFieldsValue({
                bopCode: optionsbopCode[0].value,
                unStandTypeId: record.id,
                productCode: record.productCode,
                productDesc: record.productDesc,
              });
            }
          }}
        >
          工艺
        </a>,
        <a
          key="processinfoKey4"
          onClick={() => {
            settheunStandTypeId(record.id);
            setthebopcode(record.bopCode);
            setthetypecode(record.productCode);
            setthetypename(record.productType);
            setthedesc(record.productDesc);
            setModalVisit3(true);
          }}
        >
          工时
        </a>,
        <a
          key="fileinfo4"
          onClick={() => {
            history.push({
              pathname: '/design/fileInfo',
              state: {
                infoId: record.infoId,
                reviewState: record.reviewState,
              },
            });
          }}
        >
          附件
        </a>,
      ],
    },
  ];

  // 选中项目，导出工时模板
  const rowSelection = {
    onChange: (selectedRowKeys: React.Key[], selectedRows: string[]) => {
      const temp: string[] = [];
      if (selectedRows !== null) {
        selectedRows.map((item) => {
          temp.push({
            projectCode: item.projectCode,
            projectInfoId: item.infoId,
            projectName: item.projectName,
          });
        });
      }
      setSelections(temp); //保存项目信息
    },
  };

  // 上传工时模板提交
  const workhour_upload = async () => {
    setConfirmLoading4(true);
    form
      .validateFields()
      .then(async () => {
        const res = { ...form.getFieldsValue() };
        const formData = new window.FormData();
        res.file.fileList.map((file: any) => {
          formData.append('file', file.originFileObj);
        });
        res.file = formData;
        const result = await uploadWorkhourAndCycle({ file: res.file });
        if (result != null && result.code == 0) {
          message.success('上传成功');
          form.resetFields();
        }
        setConfirmLoading4(false);
        setModalVisit4(false);
        actionRef.current!.reload();
      })
      .catch(() => {
        setConfirmLoading4(false);
      });
  };

  /*   async function getPickingStartDate(arr) {
    for (const i in arr) {
      const resultStage = await getStageByinfoId(arr[i].infoId);
      arr[i].pickingStartDate = resultStage.data[3].stagePlanStartTime;
    }
    return arr;
  } */

  //定义Tabs的子结构的数组
  const tabList: tabType[] = [
    {
      name: 'tab1',
      label: '待提交',
      content: (
        <div>
          <ProTable
            headerTitle="项目柜体查询"
            actionRef={actionRef} //用于触发刷新操作等，看api
            rowKey="id" //表格行 key 的取值，可以是字符串或一个函数
            formRef={ref}
            // search={{
            //   labelWidth: 100,
            //   defaultCollapsed: true,
            // }}
            search={tableSearchPublicConfig}
            toolBarRender={(action, { selectedRows }) => [
              /*               <Button
                key="workhour_button"
                type="primary"
                onClick={async () => {
                  //去除重复项
                  let hash = {};
                  var newArr = selections.reduce((prev, next) => {
                    hash[next.projectCode]
                      ? ''
                      : (hash[next.projectCode] = true && prev.push(next));
                    return prev;
                  }, []);
                  // console.log(selections,'处理前的项目信息');
                  // console.log( newArr,'处理后的项目信息');
                  if (newArr.length === 0) {
                    message.info('请选择柜体');
                  } else if (newArr.length > 1) {
                    message.info('请不要选择多个项目');
                  } else {
                    exportWorkhourAndCycle(newArr[0]).then((res) => {
                      const aLink = document.createElement('a');
                      document.body.appendChild(aLink);
                      aLink.style.display = 'none';
                      aLink.href = window.URL.createObjectURL(res);
                      const filenmae = '工时模板_' + newArr[0].projectName + '.xls';
                      aLink.setAttribute('download', filenmae);
                      aLink.click();
                      document.body.removeChild(aLink);
                    });
                  }
                }}
              >
                工时模板下载
              </Button>,
              <Button
                key="workhour_upload_button"
                type="primary"
                onClick={() => {
                  setModalVisit4(true);
                  form.setFieldsValue({
                    file: '',
                  });
                }}
              >
                工时上传
              </Button>, */
              <Button
                key="button1"
                icon={<PlusOutlined />}
                onClick={() => {
                  const res = { reviewState: 0 };
                  const filters = filterTranNew(res);
                  exportBatchProduct({
                    current: 1,
                    pageSize: 5000,
                    filters: filters,
                  }).then((res) => {
                    const aLink = document.createElement('a');
                    document.body.appendChild(aLink);
                    aLink.style.display = 'none';
                    aLink.href = window.URL.createObjectURL(res);
                    aLink.setAttribute('download', `BatchProduct.xls`);
                    aLink.click();
                    document.body.removeChild(aLink);
                  });
                }}
                type="primary"
              >
                导出
              </Button>,
            ]}
            request={async (params = {}, sort, filter) => {
              const res = { ...params, reviewState: 0 };
              const sorters = sortTran(sort);
              // const filters = filterTranNew(res);
              //修改为or的形式
              const filters = [
                {
                  andOr: 'or',
                  field: 'reviewState',
                  operator: 'eq',
                  value: 0,
                },
                {
                  andOr: 'or',
                  field: 'reviewState',
                  operator: 'eq',
                  value: 3,
                },
              ];
              // result:当前页面结果，result_nofilter：当前页面数据数量，result2：待审批数量
              const [result, result_nofilter, result2] = await Promise.all([
                getBatchProductByPage({
                  ...params,
                  sorters: sorters,
                  filters: filters,
                }),
                getBatchProductByPage({
                  ...params,
                  sorters: sorters,
                  filters: [
                    {
                      field: 'reviewState',
                      operator: 'eq',
                      value: 0,
                      andOr: 'and',
                    },
                  ],
                }),
                getBatchProductByPage({
                  ...params,
                  sorters: sorters,
                  filters: [
                    {
                      field: 'reviewState',
                      operator: 'eq',
                      value: 1,
                      andOr: 'and',
                    },
                  ],
                }),
              ]);
              setsubmitnumber(result_nofilter.data.totalElements);
              sethandlenumber(result2.data.totalElements);
              getproductbop();
              return {
                data: result.data.content,
                total: result.data.totalElements,
                success: result.success,
              };
            }}
            columns={tobeSubmitted}
            scroll={{ x: 2800, y: 'calc(100vh - 460px)' }}
            rowSelection={{
              selections,
              ...rowSelection,
            }}
          />
        </div>
      ),
    },
    {
      name: 'tab2',
      label: '待审批',
      content: (
        <div>
          <ProTable
            headerTitle="项目柜体查询"
            actionRef={actionRef_2} //用于触发刷新操作等，看api
            rowKey="id" //表格行 key 的取值，可以是字符串或一个函数
            formRef={ref}
            // search={{
            //   labelWidth: 100,
            //   defaultCollapsed: true,
            // }}
            search={tableSearchPublicConfig}
            toolBarRender={(action, { selectedRows }) => [
              <Button
                key="check_button"
                icon={<LogoutOutlined />}
                onClick={async () => {
                  if (theselectedRowKeys.length != 0) {
                    setModalVisit2(true);
                    setCreateOrUpdate2(true);
                    setFormTitle2('审核');
                  } else {
                    message.info('请选择要审核的柜体！');
                  }
                }}
                type="primary"
              >
                批量审核
              </Button>,
              <Button
                key="button2"
                icon={<PlusOutlined />}
                onClick={() => {
                  const res = { reviewState: 1 };
                  const filters = filterTranNew(res);
                  exportBatchProduct({
                    current: 1,
                    pageSize: 5000,
                    filters: filters,
                  }).then((res) => {
                    const aLink = document.createElement('a');
                    document.body.appendChild(aLink);
                    aLink.style.display = 'none';
                    aLink.href = window.URL.createObjectURL(res);
                    aLink.setAttribute('download', `BatchProduct.xls`);
                    aLink.click();
                    document.body.removeChild(aLink);
                  });
                }}
                type="primary"
              >
                导出
              </Button>,
            ]}
            request={async (params = {}, sort, filter) => {
              const res = { ...params, reviewState: 1 };
              const sorters = sortTran(sort);
              const filters = filterTranNew(res);
              // result:当前页面结果，result_nofilter：当前页面数据数量
              const [result, result_nofilter] = await Promise.all([
                getBatchProductByPage({
                  ...params,
                  sorters: sorters,
                  filters: filters,
                }),
                getBatchProductByPage({
                  ...params,
                  sorters: sorters,
                  filters: [
                    {
                      field: 'reviewState',
                      operator: 'eq',
                      value: 1,
                      andOr: 'and',
                    },
                  ],
                }),
              ]);
              sethandlenumber(result_nofilter.data.totalElements);
              getproductbop();
              return {
                data: result.data.content,
                total: result.data.totalElements,
                success: result.success,
              };
            }}
            columns={tobeexamine}
            scroll={{ x: 2730, y: 'calc(100vh - 460px)' }}
            rowSelection={{ onChange: onSelectChange }}
          />
        </div>
      ),
    },
    {
      name: 'tab3',
      label: '已审批',
      content: (
        <div>
          <ProTable
            headerTitle="项目柜体查询"
            actionRef={actionRef_3} //用于触发刷新操作等，看api
            rowKey="id" //表格行 key 的取值，可以是字符串或一个函数
            formRef={ref}
            // search={{
            //   labelWidth: 100,
            //   defaultCollapsed: true,
            // }}
            search={tableSearchPublicConfig}
            toolBarRender={(action, { selectedRows }) => [
              // <Button
              //   key="button"
              //   icon={<LogoutOutlined />}
              //   onClick={async () => {
              //     if (theselectedRowKeys.length != 0) {
              //       console.log(theselectedRowKeys);
              //       const result = await issueWorkOrderInforByPage(theselectedRowKeys);
              //       console.log(result);
              //       if (result && result.code === 0) {
              //         message.success('下发成功');
              //         settheSelectedRowKeys([]);
              //       }
              //       actionRef_3.current!.reload();
              //     } else {
              //       message.info('请选择要发布的柜体！');
              //     }
              //   }}
              //   type="primary"
              // >
              //   下发
              // </Button>,
              <Button
                key="button3"
                icon={<PlusOutlined />}
                onClick={() => {
                  const res = { reviewState: 2 };
                  const filters = filterTranNew(res);
                  exportBatchProduct({
                    current: 1,
                    pageSize: 5000,
                    filters: filters,
                  }).then((res) => {
                    const aLink = document.createElement('a');
                    document.body.appendChild(aLink);
                    aLink.style.display = 'none';
                    aLink.href = window.URL.createObjectURL(res);
                    aLink.setAttribute('download', `BatchProduct.xls`);
                    aLink.click();
                    document.body.removeChild(aLink);
                  });
                }}
                type="primary"
              >
                导出
              </Button>,
            ]}
            request={async (params = {}, sort, filter) => {
              const res = { ...params, reviewState: 2 };
              const sorters = sortTran(sort);
              const filters = filterTranNew(res);
              const result = await getBatchProductByPage({
                ...params,
                sorters: sorters,
                filters: filters,
              });
              // console.log(result, '接口返回数据tab3');
              getproductbop();
              return {
                data: result.data.content,
                total: result.data.totalElements,
                success: result.success,
              };
            }}
            columns={examined}
            scroll={{ x: 2730, y: 'calc(100vh - 460px)' }}
            rowSelection={{ onChange: onSelectChange }}
          />
        </div>
      ),
    },
    {
      name: 'tab4',
      label: '已驳回',
      content: (
        <div>
          <ProTable
            headerTitle="项目柜体查询"
            actionRef={actionRef_4} //用于触发刷新操作等，看api
            rowKey="id" //表格行 key 的取值，可以是字符串或一个函数
            formRef={ref}
            // search={{
            //   labelWidth: 100,
            //   defaultCollapsed: true,
            // }}
            search={tableSearchPublicConfig}
            toolBarRender={(action, { selectedRows }) => [
              <Button
                key="button4"
                icon={<PlusOutlined />}
                onClick={() => {
                  const res = { reviewState: 3 };
                  const filters = filterTranNew(res);
                  exportBatchProduct({
                    current: 1,
                    pageSize: 5000,
                    filters: filters,
                  }).then((res) => {
                    const aLink = document.createElement('a');
                    document.body.appendChild(aLink);
                    aLink.style.display = 'none';
                    aLink.href = window.URL.createObjectURL(res);
                    aLink.setAttribute('download', `BatchProduct.xls`);
                    aLink.click();
                    document.body.removeChild(aLink);
                  });
                }}
                type="primary"
              >
                导出
              </Button>,
            ]}
            request={async (params = {}, sort, filter) => {
              const res = { ...params, reviewState: 3 };
              const sorters = sortTran(sort);
              const filters = filterTranNew(res);
              const result = await getBatchProductByPage({
                ...params,
                sorters: sorters,
                filters: filters,
              });
              // console.log(result, '接口返回数据tab4');
              getproductbop();
              return {
                data: result.data.content,
                total: result.data.totalElements,
                success: result.success,
              };
            }}
            columns={issued}
            scroll={{ x: 3000, y: 'calc(100vh - 460px)' }}
            rowSelection={{ onChange: onSelectChange }}
          />
        </div>
      ),
    },
  ];

  // 设置工艺路径
  const handleSubmit = async () => {
    setConfirmLoading(true);
    form
      .validateFields()
      .then(async () => {
        const res = form.getFieldsValue();
        console.log(res);
        const result = await setBop(res);
        if (result != null) {
          message.success('设置工艺路径成功');
        }
        setConfirmLoading(false);
        setModalVisit(false);
        actionRef.current!.reload();
      })
      .catch(() => {
        setConfirmLoading(false);
      });
  };

  // 审核
  const handleSubmit2 = async () => {
    setConfirmLoading2(true);
    form
      .validateFields()
      .then(async () => {
        const res = { ...form.getFieldsValue() };
        const formData = new window.FormData();
        formData.append('file', file);
        res.file = formData;
        if (theselectedRowKeys.length != 0) {
          // 批量审核
          const thepara = res;
          thepara.batchProductId = theselectedRowKeys;
          // console.log(thepara,'批量审核参数');
          const result = await batchConfirmDesignReview(thepara);
          if (result != null) {
            if (res.reviewState == '2') {
              // 下发
              const result_xf = await issueWorkOrderInforByPage(theselectedRowKeys);
              // console.log(result_xf,'下发接口返回');
            }
            message.success('审核成功');
            form.resetFields();
          }
        } else {
          // 单个审批
          // console.log(res,'审核接口参数');
          const result = await confirmDesignReview(res);
          if (result != null) {
            if (res.reviewState == '2') {
              // 下发
              const result_xf = await issueWorkOrderInforByPage([res.batchProductId]);
              // console.log(result_xf,'下发接口返回');
            }
            message.success('审核成功');
            form.resetFields();
          }
        }
        setConfirmLoading2(false);
        setModalVisit2(false);
        actionRef_2.current!.reload();
        actionRef_2.current.clearSelected();
        actionRef_3.current!.reload();
        actionRef_4.current!.reload();
        // actionRef_2.current!.clearSelected();
      })
      .catch(() => {
        setConfirmLoading2(false);
      });
  };

  const onFilesChange = async (file) => {
    setFile(file);
  };
  const beforeUpload = (file) => {
    setFile(file);
    return false;
  };

  //获取工艺路径
  const getproductbop = async () => {
    // 获取工艺路径编号和名称
    const getcode = await getBopCodeAndName(null);
    const codeandname = [];
    getcode?.data.map((item: any, index: any) => {
      codeandname.push({ value: item.bopCode, label: item.bopName });
    });
    // console.log(codeandname);
    setoptionsbopCode(codeandname);
  };

  return (
    <PageHeaderWrapper title={false} breadcrumb={undefined}>
      <Tabs
        destroyInactiveTabPane
        type="card"
        animated={true}
        onChange={(value) => {
          setTabsActivekey(value - 1);
          console.log('tabs页：', value - 1);
        }}
        defaultActiveKey={
          props.location.query.tab_state == 3
            ? '4'
            : props.location.query.tab_state == 2
            ? '3'
            : props.location.query.tab_state == 1
            ? '2'
            : '1'
        }
        items={tabList.map((item, i) => {
          const id = String(i + 1);
          return {
            // label: item.label,
            label:
              i == 0 ? (
                <div className="text">
                  {item.label}
                  <div className="point">
                    <div className="number">{submitnumber}</div>
                  </div>
                </div>
              ) : i == 1 ? (
                <div className="text">
                  {item.label}
                  <div className="point">
                    <div className="number">{handlenumber}</div>
                  </div>
                </div>
              ) : (
                <div>{item.label}</div>
              ),
            key: id,
            children: <div>{item.content}</div>,
          };
        })}
      />
      <Modal
        title={formTitle}
        visible={modalVisit}
        onOk={handleSubmit}
        confirmLoading={confirmLoading}
        onCancel={() => setModalVisit(false)}
        destroyOnClose
      >
        <Form
          name="wrap"
          labelCol={{ flex: '110px' }}
          labelAlign="left"
          labelWrap
          form={form}
          wrapperCol={{ flex: 1 }}
          colon={false}
        >
          <Form.Item
            label="批次柜体id"
            name="unStandTypeId"
            rules={[{ required: true, message: '请输入批次柜体id!' }]}
            hidden={true}
          >
            <Input disabled />
          </Form.Item>
          <Form.Item
            label="柜体编号"
            name="productCode"
            // rules={[{ required: true, message: '请输入柜体编号!' }]}
          >
            <Input disabled />
          </Form.Item>
          <Form.Item
            label="柜体描述"
            name="productDesc"
            // rules={[{ required: true, message: '请输入柜体描述!' }]}
          >
            <Input disabled />
          </Form.Item>
          <Form.Item
            label="工艺路径"
            name="bopCode"
            rules={[{ required: true, message: '请选择工艺路径!' }]}
          >
            <Select
              disabled={recordInfo?.reviewState == 1}
              placeholder="请选择工艺路径"
              onChange={(value) => {}}
              options={optionsbopCode}
            />
          </Form.Item>
        </Form>
      </Modal>
      <Modal
        title={formTitle2}
        visible={modalVisit2}
        onOk={handleSubmit2}
        confirmLoading={confirmLoading2}
        onCancel={() => setModalVisit2(false)}
        destroyOnClose
      >
        <Form
          name="wrap"
          labelCol={{ flex: '110px' }}
          labelAlign="left"
          labelWrap
          form={form}
          wrapperCol={{ flex: 1 }}
          colon={false}
        >
          <Form.Item label="id" name="id" hidden={true}>
            <Input />
          </Form.Item>
          <Form.Item
            label="批次柜体id"
            name="batchProductId"
            // rules={[{ required: true, message: '请输入批次柜体id!' }]}
            hidden={true}
          >
            <Input />
          </Form.Item>
          <Form.Item
            label="审核结果"
            name="reviewState"
            rules={[{ required: true, message: '请选择审核结果!' }]}
          >
            <Select
              defaultValue="选择审核结果"
              options={[
                { value: '2', label: '通过' },
                { value: '3', label: '驳回' },
              ]}
            />
          </Form.Item>
          <Form.Item
            label="审核描述"
            name="reviewMemo"
            // rules={[{ required: true, message: '请输入审核描述!' }]}
          >
            <TextArea rows={4} />
          </Form.Item>
          {/* <Form.Item
            label="选择文件"
            name="file"
            // rules={[{ required: true, message: '请选择文件!' }]}
          >
            <Upload
              accept="application"
              //listType="picture-card"
              file-list="fileList"
              customRequest={onFilesChange} //通过覆盖默认的上传行为，可以自定义自己的上传实现
              showUploadList={true}
              beforeUpload={beforeUpload}
            >
              <Button icon={<UploadOutlined />}>上传文件</Button>
            </Upload>
          </Form.Item> */}
        </Form>
      </Modal>
      <Modal
        title="工序工时"
        width={1200}
        open={modalVisit3}
        onCancel={() => {
          setModalVisit3(false);
        }}
        destroyOnClose
        footer={[
          <Button
            key="back"
            onClick={() => {
              setModalVisit3(false);
            }}
          >
            关闭
          </Button>,
        ]}
      >
        <UnstandprocessInfo
          bopcode={thebopcode}
          unStandTypeId={theunStandTypeId}
          typecode={thetypecode}
          typename={thetypename}
          desc={thedesc}
        />
      </Modal>
      <Modal
        title="上传工时周期"
        visible={modalVisit4}
        onOk={workhour_upload}
        confirmLoading={confirmLoading4}
        onCancel={() => setModalVisit4(false)}
        destroyOnClose
      >
        <Form
          name="wrap"
          labelCol={{ flex: '110px' }}
          labelAlign="left"
          labelWrap
          form={form}
          wrapperCol={{ flex: 1 }}
          colon={false}
        >
          <Form.Item
            label="上传文件"
            name="file"
            rules={[{ required: true, message: '请上传工时周期文件!' }]}
          >
            <Upload
              accept="application"
              //listType="picture-card"
              file-list="fileList"
              customRequest={onFilesChange} //通过覆盖默认的上传行为，可以自定义自己的上传实现
              showUploadList={true}
              beforeUpload={beforeUpload}
            >
              <Button icon={<UploadOutlined />}>上传文件</Button>
            </Upload>
          </Form.Item>
        </Form>
      </Modal>
    </PageHeaderWrapper>
  );
};
export default BatchProduct;
